package handler

import (
	"fmt"
	"gomicro/httpMicro/httpServer/service"
	"gomicro/httpMicro/model"

	"github.com/kataras/iris/v12"
	"github.com/kataras/iris/v12/mvc"
)

//学生服务管理实现
type StudentHandlerCuda struct {
	Ctx  iris.Context
	Sip *service.StudentSriImp
	Tag string
}

func (c *StudentHandlerCuda) PostMicroinsert() mvc.Result {

	var ms model.Student
	err := c.Ctx.ReadJSON(&ms)
	fmt.Println(ms)
	if err != nil{
		return mvc.Response{
			Object : err,
		}
	}

	var t = service.StudentSriImp{}
	c.Sip = &t

	res := c.Sip.InesrtSri(&ms)
	return mvc.Response{
        Object : res,
    }
}

func (c *StudentHandlerCuda) PostMicrodelete() mvc.Result {

	var p map[string]string
	err := c.Ctx.ReadJSON(&p)
	if err != nil{
		return mvc.Response{
			Object : err,
		}
	}

	var t = service.StudentSriImp{}
	c.Sip = &t

	res := c.Sip.DeleteSri(p["name"])
	return mvc.Response{
		Object : res,
	}
}

func (c *StudentHandlerCuda) PostMicroupdate() mvc.Result {

	var ms model.Student
	err := c.Ctx.ReadJSON(&ms)
	if err != nil{
		return mvc.Response{
			Object : err,
		}
	}

	var t = service.StudentSriImp{}
	c.Sip = &t

	res := c.Sip.UpdateSri(&ms)

	return mvc.Response{
		Object : res,
	}
}

func (c *StudentHandlerCuda) PostMicroquery() mvc.Result {
	var t = service.StudentSriImp{}
	c.Sip = &t

	res := c.Sip.QuerySri()
	return mvc.Response{
		Object : res,
	}
}
